import Modal from './confirm'

let modalInstance

function getModalInstance() {
  modalInstance = modalInstance || Modal.newInstance()

  return modalInstance
}

function confirm(options) {
  let instance = getModalInstance()

  options.onRemove = function() {
    modalInstance = null
  }

  instance.show(options)
}

// 消息框
Modal.info = function(props = {}) {
  props.showCancel = false
  props.okText = props.okText || '知道了'
  return confirm(props)
}

// 确认取消框
Modal.confirm = function(props = {}) {
  props.showCancel = true
  return confirm(props)
}

// 移除 modal
Modal.remove = function() {
  if(!modalInstance) return false

  const instance = getModalInstance()

  instance.remove()
}

export default Modal
